/*
 * @Author: 0x9DEFA478
 * @Date: 2021-07-27 23:01:22
 * @LastEditTime: 2021-07-28 00:05:53
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#include "W25Q128_sim.h"
#include "Peripheral.h"




//跳转到应用程序 返回不为0 失败
static int JumpToApplication(void);

//加载ITCM数据
static void ITCM_upLoad(void);

void JumpBoot(){

  

  ITCM_upLoad();//加载ITCM代码
  __DSB();
  __ISB();

  JumpToApplication();//跳转到应用程序



  
}





//加载ITCM数据
static void ITCM_upLoad(){
  

  W25Q_sim_Init();
  W25Q_sim_ReadData(0,(unsigned char *)0,16*1024);

}





//应用程序基地址
#define vApplicationAddr          (0x00000000U)

#define vApplicationEntryAddr  (vApplicationAddr+0x00000004U)

typedef void (*AppEntry_Def)(void);

#define cApplicationEntry   ((AppEntry_Def)*((Huint32*)vApplicationEntryAddr))

//跳转到应用程序 返回不为0 失败
static int JumpToApplication(){

  volatile Huint32* Addr;
  volatile Huint32 SP_Addr;
  volatile Huint32 Entryddr;

  //中断向量表由应用程序设置
  //SCB->VTOR=0x0U|0x0U;//设置中断向量表

  Addr=(volatile Huint32*)vApplicationAddr;
  SP_Addr=Addr[0];
  Entryddr=Addr[1];

  //程序入口地址范围判定
  if((Entryddr>0x00000FFFFU)||(Entryddr<0x00000004U))
  {
    return -1;
  }

  __set_MSP(SP_Addr);
  __set_CONTROL(0);
  __ISB();

  cApplicationEntry();

  for(;;){}

}
